<?php
namespace app\controllers;

use yii\web\Controller;
use app\models\ActivityGoods;
use app\utils\Redis;

class IndexController extends Controller{
    public function actionIndex(){
        $request    = \YII::$app->request;
        $number     = $request->get('number');
        $info = ActivityGoods::find()->select('goods_id')->orderBy("id desc")->limit($number)->asArray()->all();

        return json_encode(['code'=>200,'msg'=>'请求成功','data'=>$info]);
    }

    public function actionRedis(){
        $data = ActivityGoods::find()->select('goods_id,yjsx_id,sxzh_id')->orderBy("id desc")->asArray()->all();

        Redis::set("activity_list",$data);

        $res = Redis::get("activity_list");

        return json_encode(['code'=>200,'msg'=>'请求成功','data'=>$res]);
    }

    public function actionTest(){
        $total_price    = 120;
        $first_pay      = 20;
        $stages         = 3;
        $stages_amount  = $total_price-$first_pay;

        $each_amount    = number_format($stages_amount/$stages,2,'.','');
        if($each_amount*$stages != $stages_amount){
            $each_amount    = number_format($stages_amount/$stages,2,'.','');;
            $stages_amount2 = $each_amount*$stages;

            $first_pay      = $first_pay+($stages_amount-$stages_amount2);
            $stages_amount  = $stages_amount2;
        }

        var_dump($first_pay,$stages_amount);exit;
    }
}
